package junit;

import junit.framework.Assert;
import myExceptions.MyFileException;

import org.junit.Before;
import org.junit.Test;

import questionary.MultMultAnsQ;
import questionary.MultOneAnsQ;
import questionary.NumberQ;
import questionary.SimpleQ;
import questionary.TrueFalseQ;

public class QuestionTest {
	private SimpleQ q1;
	private NumberQ q2;
	private MultOneAnsQ q3;
	private MultMultAnsQ q4;
	private TrueFalseQ q5;
	
	private String [] optionsQtype3 = {"opcion 1", "opcion 2", "opcion 3"};
	private String [] optionsQtype4 = {"opcion 1", "opcion 2", "opcion 3", "opcion 4"};
	private String [] answerQtype4 = {"opcion 1","opcion 4"};
	
	
	@Before
	public void init() throws MyFileException {
		q1 = new SimpleQ("pregunta de tipo 1", "respuesta de tipo 1", 1, 5);
		q2 = new NumberQ("pregunta de tipo 2", "2", 2, 3);
		q3 = new MultOneAnsQ("pregunta de tipo 3", "opcion 1", optionsQtype3, 0, 4);
		q4 = new MultMultAnsQ("pregunta de tipo 4", answerQtype4, optionsQtype4, 1, 6);
		q5 = new TrueFalseQ("pregunta de tipo 5", "verdadero", 2, 3);
	}
	
	@Test
	public void testSimpleQ() {
       Assert.assertTrue(q1.isCorrect("respuesta de tipo 1"));
       Assert.assertFalse(q1.isCorrect(new String [2]));
       Assert.assertTrue(q1.getScore() == 5);
       Assert.assertTrue(q1.getType() == 1);
	}
	
	@Test
	public void testNumberQ() {
		Assert.assertTrue(q2.isCorrect(2));
	    Assert.assertFalse(q2.isCorrect(new String [2]));
	    Assert.assertTrue(q2.getScore() == 3);
	    Assert.assertTrue(q2.getType() == 2);
	}

	@Test
	public void testMultOneAnsQ() {
		Assert.assertTrue(q3.isCorrect("opcion 1"));
	    Assert.assertFalse(q3.isCorrect(new String [2]));
	    Assert.assertTrue(q3.getScore() == 4);
	    Assert.assertTrue(q3.getType() == 3);
	}
	
	@Test
	public void testMultMultAnsQ() {
		Assert.assertFalse(q4.isCorrect(answerQtype4));
	    Assert.assertFalse(q4.isCorrect(new String [2]));
	    Assert.assertTrue(q4.getScore() == 6);
	    Assert.assertTrue(q4.getType() == 4);
	}
	
	@Test
	public void testTrueFalseQ() {
		Assert.assertTrue(q5.isCorrect("verdadero"));
	    Assert.assertFalse(q5.isCorrect(new String [2]));
	    Assert.assertTrue(q5.getScore() == 3);
	    Assert.assertTrue(q5.getType() == 5);
	}
	
	

}
